//
//  TTCategoryDao.m
//  02-分类界面
//
//  Created by peironggao on 2017/10/28.
//  Copyright © 2017年 gaopeirong. All rights reserved.
//

#import "TTCategoryDao.h"

@interface TTCategoryDao ()

@end

@implementation TTCategoryDao

- (void)loadAllCategoriesComplete:(void(^)(NSArray<TTCactegoryModel *> *categories))complete
                             fail:(void(^)(NSError *error))fail
{
    [self.netHelper postRequestWithURLString:@"https://www.shiguangkey.com/api/cate/query" params:nil success:^(id responseObject) {
        NSArray *list = [[responseObject objectForKey:@"data"] objectForKey:@"list"];
        NSMutableArray *categories = [NSMutableArray arrayWithCapacity:list.count];
        for (NSDictionary *item in list)
        {
            TTCactegoryModel *c = [TTCactegoryModel categoryWithDictionary:item];
            [categories addObject:c];
        }
        if (complete)
        {
            complete(categories);
        }
    } failure:^(NSError *error) {
        if (fail)
        {
            fail(error);
        }
    }];
}

@end
